NumericRange

Ecng.ComponentModel

Represents a numeric range for supporting generic math operations.

Implements: IRange<T>, IRange, ICloneable

Constructors

NumericRange
public NumericRange(TNumber min, TNumber max)
numericRange = NumericRange(min, max)

Initializes a new instance of the NumericRange struct.

min
The lower bound of the range (inclusive).
max
The upper bound of the range (inclusive).

Properties

Length
public TNumber Length { get; }
value = numericRange.Length

Gets the range length computed as Max minus Min.

Max
public TNumber Max { get; }
value = numericRange.Max

Gets the upper bound of the range (inclusive).

Min
public TNumber Min { get; }
value = numericRange.Min

Gets the lower bound of the range (inclusive).

Methods

Contains
public bool Contains(TNumber value)
result = numericRange.Contains(value)

Determines whether the specified value is contained in the current range (inclusive).

value
The value to test.

Returns: true if lies in [Min, Max]; otherwise false.

Contains
public bool Contains(NumericRange<TNumber> other)
result = numericRange.Contains(other)

Determines whether the specified range is completely contained in the current range.

other
The range to test.

Returns: true if is inside this range; otherwise false.

Intersect
public NumericRange<TNumber>? Intersect(NumericRange<TNumber> other)
result = numericRange.Intersect(other)

Computes the intersection between the current range and .

other
The range to intersect with.

Returns: A new NumericRange describing the overlap, or null when the ranges do not intersect.

SubRange
public NumericRange<TNumber> SubRange(TNumber min, TNumber max)
result = numericRange.SubRange(min, max)

Creates a sub-range from the current range with the specified bounds.

min
The minimum bound of the sub-range.
max
The maximum bound of the sub-range.

Returns: The sub-range within the current range.

ToString
public override string ToString()
result = numericRange.ToString()

Returns a string that represents the current range using the format "{Min: X Max: Y}".

Returns: A string representation of the range.